import interpreter.Interpreter;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import table_walker.*;
import DFA.*;
import MiniREParser.MINI_RE_Parser;
import nfa_generator.*;
import ast_generator.*;
import Scanner.*;

public class Scanner {	
	
	public static void main(String[] args) throws FileNotFoundException,IOException {
		String tokenSpecFile = "Test2/token_spec.txt";
		String scriptFile = "Test2/script2.txt";
		if(args.length == 2) {
			tokenSpecFile = args[0];
			scriptFile = args[1];
			System.out.println("You chose token specification at \"" + tokenSpecFile + "\" and script file at \"" + scriptFile + "\".");
		}
		else {
			System.out.println("Filepaths not given, token specification will default to \"" + tokenSpecFile + "\" and script file will default to \"" + scriptFile + "\".");
		}
		
		try {
			MiniREScanner scanner = new MiniREScanner(tokenSpecFile);
			
			ArrayList<Token> tokenList = (ArrayList<Token>) scanner.scan(scriptFile);
			
			MINI_RE_Parser parser = new MINI_RE_Parser(tokenList);
			
			ArrayList<List<String>> statements = parser.run();
			
			Interpreter interpreter = new Interpreter(statements);
			
			interpreter.interperate();
		} 
		catch (FileNotFoundException e ) {
			System.out.println("ERROR: Invalid file path or files do not exist");
		}
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}